package com.zzptc.syl.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.zzptc.syl.myapplication.R;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    ListView listView;
    List<Student> listStu;
    private static final String TAG = "MainActivity";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        listView=findViewById(R.id.lv_stu);
        listStu =new ArrayList<>();

        for(int i=0;i<=100;i++){
            Student student = new Student(R.mipmap.xiong, i, "姓名" + i, new Date() + "");
            listStu.add(student);
        }
        for (Student s: listStu) {
            Log.d(TAG, s.getName());
        }
        MyAdapter myAdapter=new MyAdapter();
        listView.setAdapter(myAdapter);

    }

    class MyAdapter extends BaseAdapter{

        @Override
        public int getCount() {
            return listStu.size();
        }

        @Override
        public Object getItem(int position) {
            return null;
        }

        @Override
        public long getItemId(int position) {
            return 0;
        }

        @SuppressLint("SetTextI18n")
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            Student student = listStu.get(position);
            @SuppressLint("ViewHolder")
            View view1 = View.inflate(MainActivity.this,R.layout.item_stu,null);
            ImageView ivPic = view1.findViewById(R.id.im_pic);
            ivPic.setImageResource(R.mipmap.xiong);
            TextView tvId =view1.findViewById(R.id.tv_id);
            tvId .setText(student.getId()+"");//要将整数转成字符串
            TextView tvName =view1.findViewById(R.id.tv_name);
            tvName .setText(student.getName());
            TextView tvDate =view1.findViewById(R.id.tv_date);
            tvDate .setText(student.getDate());
            return view1;
        }
    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.my_menu,menu);
        return true;
    }
}


